package com.cf.timer;

import com.cf.core.stage.Stage;
import lombok.extern.slf4j.Slf4j;

/**
 * game-server-HertBeatTask
 *
 * @author <a href="2428922347@qq.com">Zhu mingming</a>
 * @info
 * @since 2018/4/28 下午 03:31
 */
@Slf4j
public abstract class HeartBeatTask extends ExpirationTask {

    private Stage stage;

    public HeartBeatTask(Integer beatStepSecond, Stage stage) {
        super(beatStepSecond);
        this.stage = stage;
    }

    @Override
    public void run() {
        try {
            doTask();
        } catch (Exception e) {
            log.error("执行心跳任务失败！", e);
        }
    }

    /**
     * 获取当前任务所指向的stage
     *
     * @return
     */
    public Stage getStage() {
        return stage;
    }

    protected abstract void doTask();


    @Override
    public String getTaskDispatchId() {
        return this.stage.getStageNum();
    }
}
